﻿/*
 * SarsPacketMessageImporter.cs
 * SARS Packet message importer class.
 */
using System;
using System.Collections.Generic;

namespace LibSars
{
	/// <summary>
	/// Description of SarsPacketMessageGenerator.
	/// </summary>
	public class SarsPacketMessageImporter{
		static List<SarsPacketMessage> contentPrototypes;
		private SarsPacketMessageImporter(){ }
		static SarsPacketMessageImporter(){
			contentPrototypes = new List<SarsPacketMessage>();
			contentPrototypes.Add(new SarsPacketMessageIMINURCHAT());
			contentPrototypes.Add(new SarsPacketMessageSAITHIS());
			contentPrototypes.Add(new SarsPacketMessageUHASCL());
			
		}
		public static SarsPacketMessage GenerateMessageFrom(UInt16 MType, ref byte[] payload){
			if (MType == 0)
				return SarsPacketMessageURPSEUDO.Instance;
			foreach(SarsPacketMessage contentProto in contentPrototypes){
				if (contentProto.GetMTypeInt() == MType){
					SarsPacketMessage contentCopy = contentProto.Clone();
					contentCopy.FromBytes(ref payload);
					return contentCopy;
				}
			}
			return SarsPacketMessageURPSEUDO.Instance;
		}
	}
}
